<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   Python文本分析：本·拉登最常念叨什么？  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/21929.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466460993: Accept with keywords: (title(0.4):Python,拉登,文本,数盟,社区, topn(0.4):初始化,书架,接下来,实体,数盟,深度学习,情感,文件夹,数据分析,文件,遍历,文件名,Python,文档,文章,数据,字典,网页,函数,python,功能,链接,脚本,拉登,文本,网站,代码,人工智能,模块,识别).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    Python文本分析：本·拉登最常念叨什么？
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    Python文本分析：本·拉登最常念叨什么？ | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,69] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech/analysis">
       数据分析
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/21929.html">
          Python文本分析：本·拉登最常念叨什么？
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          841 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech/analysis" rel="category tag">
          数据分析
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        2015年，美国官方解密了一系列有关本·拉登的文件，其中最引人瞩目的，是美国国家情报总监办公室（The Office of the Director of National Intelligence）在其官网上列出的“本·拉登的书架”。
       </p>
       <p>
        曝光的这份阅读清单涉及书籍和其他材料400余种。其中包含了已解密的书信等文档103份、公开发表的美国政府文件75份、英文书籍39册、恐怖组 织发表的材料35份、与法国有关的材料19份、媒体文章33篇、其他宗教文档11份、智库或其他研究40种、软件或技术手册30份，及一些零散资料。
       </p>
       <p>
        在本文中，我们将学习如何分析PDF文档，并且利用AlchemyAPI来进行实体抽取分析，看看本·拉登在这些信件中最常提到的10个实体是什么。
       </p>
       <p>
        <img src="http://ww1.sinaimg.cn/mw690/006faQNTgw1f13uqwr6tcj30mx0bvdhy.jpg"/>
       </p>
       <h2 id="alchemyapi">
        什么是AlchemyAPI？
       </h2>
       <p>
        <img src="http://ww4.sinaimg.cn/mw690/006faQNTgw1f13tvh1wflj30m609dwfl.jpg"/>
       </p>
       <p>
        AlchemyAPI是IBM旗下的一家公司，具有深度学习的自然语言处理和图片识别技术，可利用人工智能分析理解网页、文档、电子邮件、微博等形式的内容。它还将同Google 一样的神经网络分析技术应用其中。
       </p>
       <p>
        AlchemyAPI目前共提供了12个文本分析功能：实体抽取（entitiy extraction），情感分析，关键字抓取，概念标识，关系提取，分类识别，作者提取，语言识别，文本提取，微格式分析，订阅内容识别，数据连接等。
       </p>
       <p>
        接下来，我们开始进行准备工作。
       </p>
       <blockquote>
        <p>
         本文中的代码大部分来自
         <a href="http://automatingosint.com/blog/2015/05/osint-python-analyze-bin-ladins-bookshelf/">
          automatingosint
         </a>
         ，我对源代码进行更新。目前的脚本支持Python 3。
        </p>
       </blockquote>
       <h2 id="_1">
        安装依赖包
       </h2>
       <p>
        由于美国ODNI公开的本·拉登信件都是PDF格式的，因此我们首先必须要安装能够处理PDF文档的Python包。这里，我使用的是PyPDF2。我们通过
        <code>
         pip
        </code>
        包管理器进行安装：
       </p>
       <div class="codehilite">
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92cd4232284683" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           pip install pypdf2
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686b3f92cd4232284683-1">
                1
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686b3f92cd4232284683-1">
                <span class="crayon-e">
                 pip
                </span>
                <span class="crayon-e">
                 install
                </span>
                <span class="crayon-v">
                 pypdf2
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0005 seconds] -->
       </div>
       <p>
        另外，你肯定不想一封一封地手动103封书信吧？！省时省力的办法就是写个脚本把这些文档都爬取下来。由于要访问网页和解析网页，我们选择使用两个常用的第三方库：requests和BeautifulSoup 4：
       </p>
       <div class="codehilite">
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92ce2209200088" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           pip install requests beautifulsoup4
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686b3f92ce2209200088-1">
                1
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686b3f92ce2209200088-1">
                <span class="crayon-e">
                 pip
                </span>
                <span class="crayon-e">
                 install
                </span>
                <span class="crayon-e">
                 requests
                </span>
                <span class="crayon-v">
                 beautifulsoup4
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0006 seconds] -->
       </div>
       <h2 id="alchemyapi-key">
        获取免费AlchemyAPI Key
       </h2>
       <p>
        AlchemyAPI是IBM旗下的一家公司，具有深度学习的自然语言处理和图片识别技术，可利用人工智能分析理解网页、文档、电子邮件、微博等形 式的内容。它还将同Google 一样的神经网络分析技术应用其中。AlchemyAPI目前共提供了12个文本分析功能：实体抽取（entitiy extraction），情感分析，关键字抓取，概念标识，关系提取，分类识别，作者提取，语言识别，文本提取，微格式分析，订阅内容识别，数据连接等。
       </p>
       <p>
        AlchemyAPI有一个免费的基础服务包，每天的事务处理上限为1000次。在本文中，我们将使用他们的实体抽取服务来执行文本分析。
       </p>
       <p>
        获取免费AlchemyAPI Key非常简单，只需要
        <a href="http://www.alchemyapi.com/api/register.html">
         填写一个表单
        </a>
        即可，输入自己的邮箱地址。
       </p>
       <p>
        申请处理完成之后，你就可以在邮箱中看到发送给你的API Key了。
       </p>
       <p>
        <img src="http://ww1.sinaimg.cn/mw690/006faQNTgw1f13tgh8r7zj310m03eaay.jpg"/>
       </p>
       <h2 id="alchemy-python-sdk">
        安装Alchemy Python SDK
       </h2>
       <p>
        获得API Key之后，我们可以通过AlchemyAPI提供的Python SDK和HTTP REST接口调用其提供的文本分析服务。在本文中，我们选择安装SDK的方式。
       </p>
       <p>
        PyPI上之前有AlchemyAPI包，但是后来移除了下载包，因此我们不能使用pip来安装，只能通过Git克隆Python SDK的代码库或是直接下载代码库:
       </p>
       <div class="codehilite">
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92cea669033884" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           git clone https://github.com/AlchemyAPI/alchemyapi_python.git
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686b3f92cea669033884-1">
                1
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686b3f92cea669033884-1">
                <span class="crayon-e">
                 git
                </span>
                <span class="crayon-r">
                 clone
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 https
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-c">
                 //github.com/AlchemyAPI/alchemyapi_python.git
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0006 seconds] -->
       </div>
       <p>
        接下来，我们要把申请到的API Key与SDK关联起来。打开终端，进入SDK文件夹，然后按下面的示例执行alchemyapi.py文件：
       </p>
       <div class="codehilite">
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92cf0094302226" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           cd alchemyapi_python
python alchemyapi.py YOUR_API_KEY # 将YOUR_API_KEY替换成你收到的Key
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686b3f92cf0094302226-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cf0094302226-2">
                2
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686b3f92cf0094302226-1">
                <span class="crayon-e">
                 cd
                </span>
                <span class="crayon-e">
                 alchemyapi_python
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cf0094302226-2">
                <span class="crayon-e">
                 python
                </span>
                <span class="crayon-v">
                 alchemyapi
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 py
                </span>
                <span class="crayon-v">
                 YOUR_API_KEY
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 将YOUR_API_KEY替换成你收到的Key
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0008 seconds] -->
       </div>
       <p>
        为确保SDK正常安装，可以按照提示运行example.py查看演示程序：
       </p>
       <div class="codehilite">
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92cf7685659494" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           python example.py
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686b3f92cf7685659494-1">
                1
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686b3f92cf7685659494-1">
                <span class="crayon-e">
                 python
                </span>
                <span class="crayon-v">
                 example
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 py
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0010 seconds] -->
       </div>
       <p>
        如果最后出现了下图的文字，就证明SDK安装正确，API Key也可以使用。
       </p>
       <p>
        <img src="http://ww4.sinaimg.cn/mw690/006faQNTgw1f13telx4vvj30w00oyah8.jpg"/>
       </p>
       <h2 id="_2">
        下载文档
       </h2>
       <p>
        然后就到了怎么自动将103份PDF文档下载到本地了。
       </p>
       <p>
        我们可以写一个简单的Python脚本来完成这项工作，但是我选择把它封装在download_bld_documents这个函数里，因为我想把所有的代码都放在一个脚本里，这样大家就可以直接运行这个脚本，等待一段时间，就可以看到最后的结果了。
       </p>
       <p class="s-Atom">
        这个函数写的比较简单，但是已经能够满足我们的需求了。
       </p>
       <p>
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92cfd736944477" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           Python
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          def download_bld_documents():
    """Download Bin Laden's Declassified documents from ODNI."""
    import os
    import time
    import requests    
    from bs4 import BeautifulSoup

    # 创建一个名为“pdfs”的文件夹，用于保存所有下载的PDF文档。
    try:
        os.mkdir("pdfs")
    except:
        pass

    # 获取ODNI网站上有关本·拉登书架的网页，
    # 将其交给Beautiful Soup，以进行HTML解析。
    response = requests.get(
        "http://www.dni.gov/index.php/resources/bin-laden-bookshelf?start=1")

    if response.status_code == 200:

        html = BeautifulSoup(response.content)

    link_list = []
    # 从网页中第54个超链接开始，我们遍历所有的文档链接，
    # 仅保留那些我们所需要的链接：即含有“pdf”但不包含“Arabic”
    # 字样的链接。我们将满足要求的链接保存到列表`link_list`中。

    for i in html.findAll("a")[54:]:
        if "pdf" in i['href'] and "Arabic" not in i.text:
            link_list.append("http://www.odni.gov%s" % i['href'])
    # 接下来，我们遍历列表中所有的元素，
    # 从原链接中获取PDF的文件名，
    #然后从ODNI网站下载相应的文档。

    for i in link_list:
        response = requests.get(i)
        file_name = i.split("/")[::-1][0]
        fd = open("pdfs/%s" % file_name, "wb")
        fd.write(response.content)
        fd.close()

        time.sleep(1)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-28">
               28
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-29">
               29
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-30">
               30
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-31">
               31
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-32">
               32
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-33">
               33
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-34">
               34
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-35">
               35
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-36">
               36
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-37">
               37
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-38">
               38
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-39">
               39
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-40">
               40
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92cfd736944477-41">
               41
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92cfd736944477-42">
               42
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-1">
               <span class="crayon-r">
                def
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                download_bld_documents
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                """Download Bin Laden's Declassified documents from ODNI."""
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                os
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                time
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                requests
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-6">
               <span class="crayon-e">
               </span>
               <span class="crayon-st">
                from
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                bs4
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                BeautifulSoup
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-7">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 创建一个名为“pdfs”的文件夹，用于保存所有下载的PDF文档。
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                try
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                os
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                mkdir
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "pdfs"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                except
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                pass
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-13">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-14">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 获取ODNI网站上有关本·拉登书架的网页，
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 将其交给Beautiful Soup，以进行HTML解析。
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-16">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                requests
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                get
               </span>
               <span class="crayon-sy">
                (
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-17">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "http://www.dni.gov/index.php/resources/bin-laden-bookshelf?start=1"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-18">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                status_code
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                200
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-20">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-21">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                html
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                BeautifulSoup
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                content
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-22">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-23">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                link_list
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-24">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 从网页中第54个超链接开始，我们遍历所有的文档链接，
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-25">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 仅保留那些我们所需要的链接：即含有“pdf”但不包含“Arabic”
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-26">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 字样的链接。我们将满足要求的链接保存到列表`link_list`中。
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-27">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-28">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                html
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                findAll
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "a"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                54
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-29">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "pdf"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'href'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                and
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "Arabic"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                not
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                text
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-30">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                link_list
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                append
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "http://www.odni.gov%s"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'href'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-31">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 接下来，我们遍历列表中所有的元素，
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-32">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 从原链接中获取PDF的文件名，
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-33">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                #然后从ODNI网站下载相应的文档。
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-34">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-35">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                link_list
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-36">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                requests
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                get
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-37">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                file_name
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                i
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                split
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "/"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-o">
                ::
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ]
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-38">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                fd
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                open
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "pdfs/%s"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                file_name
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "wb"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-39">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                fd
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                write
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                content
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-40">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                fd
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                close
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92cfd736944477-41">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92cfd736944477-42">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                time
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                sleep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0310 seconds] -->
       <p>
       </p>
       <p class="s-Atom">
        由于文件数量比较多，因此在最终执行脚本时，耗费在文件下载的时间可能会比较长。如果你从ODNI网站下载的速度非常慢，那么可以前往我的百度网盘下载，但是在最终执行时要对脚本做修改。只需要执行下文中的函数即可。
       </p>
       <blockquote>
        <p>
         <strong>
          在微信号中，回复“laden”即可获得分享链接及提取码。
         </strong>
        </p>
       </blockquote>
       <h2 id="_3">
        处理文档
       </h2>
       <p>
        下面，我们就可以正式对下载的PDF文档进行分析了。我们将要利用Alchemy API提供的强大工具，对这些PDF文档进行实体抽取（entitiy extraction）分析。通过实体分析，我们可以了解本·拉登在这些信件和文件中，谈到最多的人、地方或东西是什么。
       </p>
       <p>
        所以，我们要一一打开这些PDF文件，从文档中提取所有的文本，然后将其提交至Alchemy进行分析处理。在处理每一个文档时，我们可以得到其中的实体数据，最后将所有文档的分析数据结合在一起，就可以得到出现频率最高的实体了。
       </p>
       <p>
        我们将这部分代码封装在process_documents函数中：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92d06493964410" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           Python
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          def process_documents():
    """Process downloaded documents using AlchemyAPI."""

    # 导入所需要的模块，包括我们安装的PyPDF2和AlchemyAPI。
    import PyPDF2
    import glob
    import time    
    from collections import Counter    
    from alchemyapi import AlchemyAPI

    alchemyapi = AlchemyAPI() # 初始化AlchemyAPI。
    file_list = glob.glob("pdfs/*.pdf") 
    # 通过`glob`模块获取我们下载的所有PDF文件的文件名。
    entities = {} 
    # 我们要使用`entities`字典来保存每个PDF文档的分析结果。    # 下面的for循环将遍历所有的PDF文件
    for pdf_file in file_list:

        # read in the PDF
        print("[*] Parsing %s" % pdf_file)

    # 初始化一个PyPDF2对象，用于保存从PDF文档中提取的文本数据
        pdf_obj = PyPDF2.PdfFileReader(open(pdf_file, "rb"))

    # 创建一个空字符串，用于后续构建这个PDF的全部文本数据
        full_text = ""

        # 从每页中提取文本数据
        for page in pdf_obj.pages:
            full_text += page.extractText()
    # 接下来我们使用Alchemy API进行实体抽取
        print("[*] Sending %d bytes to the Alchemy API" % len(full_text))
        # 调用AlchemyAPI，并明确我们提交的是文本数据（第一个参数）
        # 然后传入需要分析的文本，第三个参数代表禁用情感分析功能，
        # 因为本文中我们只关注频率最��的实体。

        response = alchemyapi.entities('text', full_text, {'sentiment': 0})

        if response['status'] == 'OK':
            # 遍历返回的全部实体数据。
            # Alchemy返回的每个实体中，都包含有`count`数据，
            # 我们要确保在`entities`字典中，将所有相同实体的count相加
            for entity in response['entities']:
                # add each entity to our master list
                if entity['text'] in entities:
                    entities[entity['text']] += int(entity['count'])
                else:
                    entities[entity['text']] = int(entity['count'])

            print("[*] Retrieved %d entities from %s" %
                  (len(entities), pdf_file))

        else:
            print("[!] Error receiving Alchemy response: %s" %
                  response['statusInfo'])

        time.sleep(1)

    # 上面的循环执行结束，我们可以统计最常见的实体，
    # 并把相关的结果打印出来了！
    entity_counter = Counter(entities)

    top_entities = entity_counter.most_common()

    # 接下来就开始打印本·拉登提到次数最多的实体吧！
    for top_entity in top_entities[0:10]:

        # most_common returns a tuple (entity,count)
        print("%s =&gt; %d" % (top_entity[0], top_entity[1]))
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-28">
               28
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-29">
               29
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-30">
               30
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-31">
               31
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-32">
               32
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-33">
               33
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-34">
               34
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-35">
               35
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-36">
               36
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-37">
               37
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-38">
               38
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-39">
               39
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-40">
               40
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-41">
               41
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-42">
               42
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-43">
               43
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-44">
               44
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-45">
               45
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-46">
               46
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-47">
               47
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-48">
               48
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-49">
               49
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-50">
               50
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-51">
               51
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-52">
               52
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-53">
               53
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-54">
               54
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-55">
               55
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-56">
               56
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-57">
               57
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-58">
               58
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-59">
               59
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-60">
               60
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-61">
               61
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-62">
               62
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-63">
               63
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-64">
               64
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-65">
               65
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-66">
               66
              </div>
              <div class="crayon-num" data-line="crayon-57686b3f92d06493964410-67">
               67
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d06493964410-68">
               68
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-1">
               <span class="crayon-r">
                def
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                process_documents
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                """Process downloaded documents using AlchemyAPI."""
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-3">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 导入所需要的模块，包括我们安装的PyPDF2和AlchemyAPI。
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                PyPDF2
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-6">
               <span class="crayon-e">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                glob
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                time
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                from
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                collections
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                Counter
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-9">
               <span class="crayon-e">
               </span>
               <span class="crayon-st">
                from
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                alchemyapi
               </span>
               <span class="crayon-r">
                import
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                AlchemyAPI
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-10">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-11">
               <span class="crayon-e">
               </span>
               <span class="crayon-v">
                alchemyapi
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                AlchemyAPI
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 初始化AlchemyAPI。
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                file_list
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                glob
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-k ">
                glob
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "pdfs/*.pdf"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 通过`glob`模块获取我们下载的所有PDF文件的文件名。
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-14">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entities
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 我们要使用`entities`字典来保存每个PDF文档的分析结果。    # 下面的for循环将遍历所有的PDF文件
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-16">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pdf_file
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                file_list
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-17">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # read in the PDF
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                print
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "[*] Parsing %s"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pdf_file
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-20">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-21">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 初始化一个PyPDF2对象，用于保存从PDF文档中提取的文本数据
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-22">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pdf_obj
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                PyPDF2
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                PdfFileReader
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-k ">
                open
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                pdf_file
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "rb"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-23">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-24">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 创建一个空字符串，用于后续构建这个PDF的全部文本数据
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-25">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                full_text
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                ""
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-26">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-27">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 从每页中提取文本数据
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-28">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                page
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pdf_obj
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                pages
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-29">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                full_text
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +=
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                page
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                extractText
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-30">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 接下来我们使用Alchemy API进行实体抽取
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-31">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                print
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "[*] Sending %d bytes to the Alchemy API"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                len
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                full_text
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-32">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 调用AlchemyAPI，并明确我们提交的是文本数据（第一个参数）
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-33">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 然后传入需要分析的文本，第三个参数代表禁用情感分析功能，
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-34">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 因为本文中我们只关注频率最��的实体。
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-35">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-36">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                alchemyapi
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                entities
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'text'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                full_text
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-s">
                'sentiment'
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-37">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-38">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'status'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'OK'
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-39">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 遍历返回的全部实体数据。
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-40">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # Alchemy返回的每个实体中，都包含有`count`数据，
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-41">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 我们要确保在`entities`字典中，将所有相同实体的count相加
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-42">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                entity
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'entities'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-43">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # add each entity to our master list
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-44">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'text'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entities
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-45">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entities
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'text'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +=
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                int
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'count'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-46">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                else
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-47">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entities
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'text'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                int
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'count'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-48">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-49">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                print
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "[*] Retrieved %d entities from %s"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-50">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-k ">
                len
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                entities
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                pdf_file
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-51">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-52">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                else
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-53">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                print
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "[!] Error receiving Alchemy response: %s"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-54">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                response
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'statusInfo'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-55">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-56">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                time
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                sleep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-57">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-58">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 上面的循环执行结束，我们可以统计最常见的实体，
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-59">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 并把相关的结果打印出来了！
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-60">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entity_counter
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                Counter
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                entities
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-61">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-62">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                top_entities
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                entity_counter
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                most_common
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-63">
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-64">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # 接下来就开始打印本·拉登提到次数最多的实体吧！
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-65">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                top_entity
               </span>
               <span class="crayon-st">
                in
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                top_entities
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-66">
              </div>
              <div class="crayon-line" id="crayon-57686b3f92d06493964410-67">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                # most_common returns a tuple (entity,count)
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d06493964410-68">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                print
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "%s =&gt; %d"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                %
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                top_entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                top_entity
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0513 seconds] -->
       <p>
       </p>
       <p>
        上面函数的最后，我们使用了Counter类来加载entities字典，并且很容易地就得出了最常见的实体。
       </p>
       <h2 id="_4">
        快速执行脚本
       </h2>
       <p>
        最后执行脚本时，一定要注意：要把脚本放在alchemyapi_python这个文件夹里。这是因为AlchemyAPI SDK并没有在Python的PATH上。
       </p>
       <p>
        为了让大家少复制粘贴，我已经把相关的操作写在一个bash脚本里。大家下载脚本后
        <strong>
         修改API KEY
        </strong>
        即可。
       </p>
       <div class="codehilite">
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686b3f92d10389978917" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           curl https://raw.githubusercontent.com/bingjin/funscripts/master/laden/bld.sh --output bld.sh
sh bld.sh
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686b3f92d10389978917-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686b3f92d10389978917-2">
                2
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686b3f92d10389978917-1">
                <span class="crayon-e">
                 curl
                </span>
                <span class="crayon-v">
                 https
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-c">
                 //raw.githubusercontent.com/bingjin/funscripts/master/laden/bld.sh --output bld.sh
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686b3f92d10389978917-2">
                <span class="crayon-e">
                 sh
                </span>
                <span class="crayon-v">
                 bld
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 sh
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0008 seconds] -->
       </div>
       <p>
        <img src="http://ww3.sinaimg.cn/mw690/006faQNTgw1f13ts8u4f3j30w80oqh1v.jpg"/>
       </p>
       <p>
        上图就是正在执行的脚本。想不想看看最终的分析结果？
       </p>
       <p>
        我直接告诉你们就太没趣了，大家可以运行脚本自己看，等待的同时可以品尝一杯咖啡。当然，剧透也是有的：
        <strong>
         伊斯兰教先知穆罕默德居然才排第七！
        </strong>
       </p>
       <p>
        你分析的结果是怎样的，留言告诉大家本·拉登提到次数最多的三个实体吧！
       </p>
       <h2 id="_5">
        结语
       </h2>
       <p>
        本文中仅使用了AlchemyAPI的实体提取功能，其他诸如关键词分析、情感分析、图像分析等功能都没有涉及。大家可以在本文的基础上，进一步发挥自己的想象力，看看还能从本·拉登的书架中得到什么信息。
       </p>
       <p>
       </p>
       <p>
        来源：编程派
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/24687.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/u16130037972892789947fm21gp0-300x157.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24687.html" rel="bookmark" title="从0开始学习 GitHub 系列之「Git 进阶」">
         从0开始学习 GitHub 系列之「Git 进阶」
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24672.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/201407171112-300x172.png"/>
        </a>
        <a class="link" href="http://dataunion.org/24672.html" rel="bookmark" title="为什么说Spark SQL远远超越了MPP SQL">
         为什么说Spark SQL远远超越了MPP SQL
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24543.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/1013-300x187.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24543.html" rel="bookmark" title="一文告诉你机器学习中进行模型评价、模型选择和算法选择的终极方法（PART I）">
         一文告诉你机器学习中进行模型评价、模型选择和算法选择的终极方法（PART I）
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24536.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/p23424357-300x193.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24536.html" rel="bookmark" title="用朴素贝叶斯进行文本分类(下)">
         用朴素贝叶斯进行文本分类(下)
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F21929.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/21929.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/21929.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>